// 本地
// export const BC_LOGIN_URL = "http://localhost:1888/#/login";
// export const OC_LOGIN_URL = "http://localhost:1888/#/wel/index"
// export const IC_LOGIN_URL = "http://192.168.1.5:1888/#/login"

// 测试服务器
//export const BC_LOGIN_URL= "http://bc-test.ninesword.com:88/#/login";
//export const OC_LOGIN_URL= "http://oc-test.ninesword.com:89/#/wel/index"
// export const IC_LOGIN_URL = "http://192.168.1.5:1888/#/login"

// 06
//export const BC_LOGIN_URL= "https://bc06.ninesword.com/#/login";
//export const OC_LOGIN_URL= "https://oc06.ninesword.com/#/wel/index"

// 正式服
// export const BC_LOGIN_URL= "https://beetlesbc.ninesword.com/#/login";
// export const OC_LOGIN_URL= "https://beetlesoc.ninesword.com/#/wel/index"
// export const IC_LOGIN_URL = "http://124.70.206.203/#/login"

/*
示例（localhost）：
DELETE FROM beetles.blade_param WHERE param_key='login.urls';
INSERT INTO beetles.blade_param(`id`,param_name,param_key,param_value,`remark`,`status`,`is_deleted`)
VALUES(1238706330076790787,'BC、OC登录URL配置','login.urls','[{hostname: ["default"], bc: "http://localhost:1888/#/login", oc: "http://localhost:1889/#/wel/index"}]','注意param_value长度',1,0);
COMMIT;

示例（beetlesbc.ninesword.com）：
DELETE FROM beetles.blade_param WHERE param_key='login.urls';
INSERT INTO beetles.blade_param(`id`,param_name,param_key,param_value,`remark`,`status`,`is_deleted`)
VALUES(1238706330076790787,'BC、OC登录URL配置','login.urls','[{hostname: ["default"], bc: "https://beetlesbc.ninesword.com/#/login", oc: "https://beetlesoc.ninesword.com/#/wel/index"}]','注意param_value长度',1,0);
COMMIT;

示例（demo）：
DELETE FROM beetles.blade_param WHERE param_key='login.urls';
INSERT INTO beetles.blade_param(`id`,param_name,param_key,param_value,`remark`,`status`,`is_deleted`)
VALUES(1238706330076790787,'BC、OC登录URL配置','login.urls','[{hostname: ["default"], bc: "https://bc06.ninesword.com/#/login", oc: "https://oc06.ninesword.com/#/wel/index"}]','注意param_value长度',1,0);
COMMIT;

示例（test，兼顾开发人员调试使用）：
DELETE FROM beetles.blade_param WHERE param_key='login.urls';
INSERT INTO beetles.blade_param(`id`,param_name,param_key,param_value,`remark`,`status`,`is_deleted`)
VALUES(1238706330076790787,'BC、OC登录URL配置','login.urls','[{hostname: ["localhost","127.0.0.1"], bc: "http://localhost:1888/#/login", oc: "http://localhost:1889/#/wel/index"},{hostname: ["default"], bc: "http://bc-test.ninesword.com:88/#/login", oc: "http://oc-test.ninesword.com:89/#/wel/index"}]','注意param_value长度',1,0);
COMMIT;
 */

function ajax(param) {
    $.ajax({
        url: param.url,
        headers: param.headers,
        async: param.async,
        type: param.method,
        data: param.data,
        success: function(data) {
            if (param.success) {
                param.success(data);
            }
        },
        error: function() {
            if (param.error) {
                param.error();
            }
        }
    });
}

let constLoginUrls = null;

function getLoginUrls() {
    if (constLoginUrls == null) {
        let param = {
            url: '/api/blade-auth/oauth/query-login-urls',
            headers: null,
            method: 'GET',
            async: false,
            data: {},
            success: (data) => {
                if (data != null && data.urls != null && data.urls.length > 0) {
                    let hostname = window.location.hostname;
                    let defaultLoginUrls = null;
                    data.urls.forEach((loginUrls) => {
                        if (loginUrls.hostname != null) {
                            if (typeof loginUrls.hostname == 'string') {
                                loginUrls.hostname = loginUrls.hostname.split(',');
                            }
                            if (loginUrls.hostname.includes(hostname)) {
                                constLoginUrls = loginUrls;
                            } else if (loginUrls.hostname.includes('default')) {
                                defaultLoginUrls = loginUrls;
                            }
                        }
                    });
                    if (constLoginUrls == null) {
                        constLoginUrls = defaultLoginUrls;
                    }
                }
            },
            error: () => {}
        };
        ajax(param);
    }
    if (constLoginUrls != null) {
        return constLoginUrls;
    }
    let loc = window.location;
    if (['bc-test.ninesword.com', 'oc-test.ninesword.com', '111.59.164.28'].includes(loc.hostname)) {
        return constLoginUrls = {
            bc: "http://bc-test.ninesword.com:88/login",
            oc: "http://oc-test.ninesword.com:89/wel/index",
            ic: "http://192.168.1.5:1888/#/login"
        };
    } else if (['beetlesbc.ninesword.com', 'beetlesoc.ninesword.com', '123.60.12.248'].includes(loc.hostname)) {
        return constLoginUrls = {
            bc: "https://beetlesbc.ninesword.com/login",
            oc: "https://beetlesoc.ninesword.com/wel/index",
            ic: "http://124.70.206.203/#/login"
        };
    } else if (['bc.adsbeetles.com', 'oc.adsbeetles.com', '119.12.169.53'].includes(loc.hostname)) {
        return constLoginUrls = {
            bc: "https://bc.adsbeetles.com/login",
            oc: "https://oc.adsbeetles.com/wel/index",
            ic: "http://124.70.206.203/#/login"
        }
    } else if (['bc06.ninesword.com', 'oc06.ninesword.com', '121.37.143.118'].includes(loc.hostname)) {
        return constLoginUrls = {
            bc: "https://bc06.ninesword.com/login",
            oc: "https://oc06.ninesword.com/wel/index",
            ic: "http://124.70.206.203/#/login"
        }
    } else {
        return constLoginUrls = {
            bc: "http://localhost:1888/login",
            oc: "http://localhost:1889/wel/index",
            ic: "http://localhost:1889/#/login"
        };
    }
}
export const BC_LOGIN_URL = getLoginUrls().bc;
export const OC_LOGIN_URL = getLoginUrls().oc;
export const IC_LOGIN_URL = getLoginUrls().ic;